<!--规则结果-->
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="my" uri="http://www.trkj.com/tr1702/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript"
	src="<c:url value="/js/jquery-easyui-1.5.5.6/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-easyui-1.5.5.6/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-easyui-1.5.5.6/locale/easyui-lang-zh_CN.js"/>"></script>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/js/jquery-easyui-1.5.5.6/themes/default/easyui.css"/>" />
<link rel="stylesheet" type="text/css"
	href="<c:url value="/js/jquery-easyui-1.5.5.6/themes/icon.css"/>" />
</head>
<body>
	<script type="text/javascript">
	var rule_result_state= function(value,row,index){
		var pic="";
		var state = row.attruState;
		if(state==0){
			pic = "<input type='checkbox' disabled='disabled'>";
		}else if(state==1){
			pic="<input type='checkbox' checked  disabled='disabled'>";
		}
		return pic;
	}
	var rule_result_button =function(value,row,index){
		var only = "";
		var edit ="";
		var del = "";
		 <my:g id="48">only = "<a style='' btn='cell_btn_only' onclick='onlyrule(" + row.attruId + ","+row.attruState+")'></a>";</my:g>
		 <my:g id="47">edit = "<a style='' btn='cell_btn_edit' onclick='editrule(" + row.attruId + ")'></a>";</my:g>
		 <my:g id="49">del = " <a btn='cell_btn_del' onclick='delrule(" + row.attruId + ")'></a>";</my:g>
		return  only +edit +del; 
	}
		/*禁用*/
		var onlyrule =function(attruId,attruState){
			$('#update-rule_result').dialog("close");
			var jy_state =1;
			if(attruState==1){
				jy_state=0;
				$.messager.confirm('确认', '您确定要打开该规则吗？', function(v){
					if(v){
						$.post("update_rule_result_state", {attruId: attruId,attruState:jy_state}, function(v){
							if(v.success){
								$('#rule_result_tb').datagrid('reload');
							}else{
								$.messager.alert('错误', v.message);
							}
						});
					}else{
						
					}
					
				}); 
			}else if(attruState==0){
				jy_state=1;
				$.messager.confirm('确认', '您确定要关闭该规则吗？', function(v){
					if(v){
						$.post("update_rule_result_state", {attruId: attruId,attruState:jy_state}, function(v){
							if(v.success){
								$('#rule_result_tb').datagrid('reload');
							}else{
								$.messager.alert('错误', v.message);
							}
						});
					}else{
						
					}
					
				}); 
			}
			
		}
		/*修改*/
		var editrule=function(attruId){
			$('#update-rule_result').dialog("open");
			$('#rule_result_update').form('load','load_attendancerule?attruId='+attruId);
		}
		/*删除*/
		var delrule= function(attruId){
			$('#update-rule_result').dialog("close");
			$.messager.confirm('确认','您确认要删除规则吗？',function(v){
				if(v){
					$.post("delete_rule_result_",{attruId:attruId},function(v){
						if(v.success){
							$('#rule_result_tb').datagrid('reload');
						}else{
							$.messager.alert('错误',v.message);
						}
					});
				}else{
					
				}
				
			});
		}
		$(function() {
			$(".add_result").linkbutton({
				onClick : function() {
					$("#dd-rule_result").dialog("open");
				}
			});
			$("#rule_result_tb").datagrid({
				onLoadSuccess:function(){
					$("a[btn=cell_btn_edit]").linkbutton({iconCls:'icon-update_red', plain:true});
					$("a[btn=cell_btn_del]").linkbutton({iconCls:'icon-delete_red', plain:true});
					$("a[btn=cell_btn_only]").linkbutton({iconCls:'icon-changes', plain:true});
				}
			});
			//模糊搜索
			$("#rule_result_seebyname").linkbutton({
				onClick:function(){
					var SeeText = $("#rule_result_seebytext").textbox("getText");
					 $("#rule_result_tb").datagrid({url:'to_attendanceruleByName?attruName='+SeeText,method:'get'});
					$("#rule_result_tb").datagrid("reload"); 
				}
			});
			//双击修改
			<my:g id="47">$('#rule_result_tb').datagrid({
				onDblClickRow: function(index, row){
					$('#update-rule_result').dialog("open");
					$('#rule_result_update').form('load','load_attendancerule?attruId='+row.attruId);
				}
			});</my:g>
			
			//

		});
		//进入时加载
		$(document).ready(function(){
			
		});
		//刷新
		$("#rule_result_reload").linkbutton({
			onClick:function(){
				$('#rule_result_tb').datagrid('reload');
			}
		});
		 
	</script>
	<table id="rule_result_tb" class="easyui-datagrid" style="width: 400px; height: 250px"
		data-options="
				fitColumns:true,
				fit:true,
       			url:'to_attendancerule',
				pagination:true,     
				pageSize:5,     
				pageList: [5,10,15,20,25], 
				rownumbers:true,
				Striped:true, 
				singleSelect:true,
				striped:true,
				toolbar:'#tool'
        ">
		<thead>
			<tr>
				<th data-options="field:'attruId',width:30,align:'center'">编号</th>
				<th data-options="field:'attruName',width:70,align:'center'">名称</th>
				<!-- <th data-options="field:'bb',width:100,align:'center'">简称</th> -->
				<th data-options="field:'attruRepeat',width:70,align:'center'">重复有效</th>
				<th data-options="field:'attruAffair',width:30,align:'center'">类别</th>
				<th data-options="field:'attruRemarks',width:80,align:'center'">备注</th>
				<th data-options="field:'attruPerson',width:50,align:'center'">创建者</th>
				<th data-options="field:'attruFounddate',width:80,align:'center'
				,formatter:function(value,row,index){
					if(value!=null){
						var date = new Date(value);
						return date.toLocaleString();
					}
						return;
				}">创建日期</th>
				<th data-options="field:'attruEndupdate',width:80,align:'center',formatter:function(value,row,index){
					if(value!=null){
						var date = new Date(value);
						return date.toLocaleString();
					}
						return;
				}">最后更新</th>
				<th data-options="field:'attruUpdate',width:80,align:'center',formatter:function(value,row,index){
					if(value!=null){
						var date = new Date(value);
						return date.toLocaleString();
					}
						return;
				}">更新日期</th>
				<th data-options="field:'attruState',width:20,align:'center',formatter:rule_result_state">
					状态
				</th>
				<th data-options="field:'xxx',width:60,formatter:rule_result_button">操作</th>   
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	<!--工具-->
	<div id="tool" style="padding-left: 30px;">
		<my:g id="46"><a class="easyui-linkbutton add_result"
			data-options="iconCls:'icon-add'">新增</a></my:g>
			<a id="rule_result_reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload'"></a>
			<input class="easyui-textbox" id="rule_result_seebytext" data-options="prompt:'请输入名称'"> <a class="easyui-linkbutton"
			data-options="text:'搜索'" id="rule_result_seebyname"> </a>
			
	</div>

	<div id="dd-rule_result" class="easyui-dialog" title="规则结果"
		data-options="
          width:400,
         height:290,
	     resizable:false,
	     modal:true,
	     closed:true,
	     buttons:[{
				text:'添加',
				width:60,
				handler:function(){
					$('#rule_result_add').form({
						url:'to_add_rule_result',
						
						onSubmit:function(params){
							
							params['attruName']=$('#rule_result_name').textbox('getText');
							params['attruRepeat']=$('#cfyx-value').val();
							params['attruAffair']=$('#lb-rule_result').val();
							if($('#rule_result_check').is(':checked')){
								params['attruState']=parseInt(1);
							}else{
								params['attruState']=parseInt(0);
							}
							params['attruRemarks']=$('#rule_result_marks').val();
								return $('#rule_result_add').form('validate');
						},
						success:function(v){
							v = eval('('+v +')');
							if(v.success){
								$.messager.alert('恭喜', '添加成功');
							}else{
								$.messager.alert('错误', '对不起，操作失败，原因：' + v.message);
							}
						$.messager.progress('close');// 如果提交成功则隐藏进度条
						$('#rule_result_tb').datagrid('reload');
						$('#rule_result_add').form('reset');
						$('#dd-rule_result').dialog('close');
						}
					}).submit();
				}
				},{
				text:'继续添加',
				width:80,
				handler:function(){
					$('#rule_result_add').form({
						url:'to_add_rule_result',
						
						onSubmit:function(params){
							
							params['attruName']=$('#rule_result_name').textbox('getText');
							params['attruRepeat']=$('#cfyx-value').val();
							params['attruAffair']=$('#lb-rule_result').val();
							if($('#rule_result_check').is(':checked')){
								params['attruState']=parseInt(1);
							}else{
								params['attruState']=parseInt(0);
							}
							params['attruRemarks']=$('#rule_result_marks').val();
								return $('#rule_result_add').form('validate');
						},
						success:function(v){
							v = eval('('+v +')');
							if(v.success){
								$.messager.alert('恭喜', '添加成功');
							}else{
								$.messager.alert('错误', '对不起，操作失败，原因：' + v.message);
							}
						$.messager.progress('close');// 如果提交成功则隐藏进度条
						$('#rule_result_tb').datagrid('reload');
						$('#rule_result_add').form('reset');
						
						}
					}).submit();
				}
				},{
				text:'取消',
				width:60,	
				handler:function(){
					$('#dd-rule_result').dialog('close');
				}
			}]
        ">
		<div style="margin-left: 16%; margin-top: 10px;">
			<form action="" id="rule_result_add" style="text-align: right;">
				<table>
					<!-- <tr>
						<td><span style="color: red;">*</span>编号</td>
						<td><input class="easyui-textbox"
							data-options="required:true"></td>
					</tr> -->
					<tr>
						<td><span style="color: red;">*</span>名称</td>
						<td><input class="easyui-textbox"
							data-options="required:true" id="rule_result_name"></td>
					</tr>
					<!-- <tr>
						<td><span style="color: red;"> </span>简称</td>
						<td><input class="easyui-textbox"></td>
					</tr> -->
					<tr>
						<td><span style="color: red;"> </span>重复有效</td>
						<td>
							<select id="cfyx-value" class="easyui-combobox" class="cfyx"
								style="width: 170px;" data-options="panelHeight:'auto'">
									<option value=""> </option>
									<option value="不考虑">不考虑</option>
									<option value="第一个">第一个</option>
									<option value="最后一个">最后一个</option>
							</select>
						</td>
					</tr>
					<tr>
						<td><span style="color: red">*</span>类别</td> 
						<td><select id="lb-rule_result" class="easyui-combobox" class="work_leibie"
								style="width: 170px;" data-options="panelHeight:'auto'">
									<option value="上班">上班</option>
									<option value="下班">下班</option>
									<option value="无">无</option>
							</select></td>
					</tr>
					<tr>
						<td><span style="color: red;"> </span>备注</td>
						<td><input class="easyui-textbox" data-options="height:60,multiline:true" id="rule_result_marks"></td>
					</tr>
					<tr>
						<td><span style="color: red;"> </span></td>
						<td><span style="padding-right:5px;">停用</span>
						<input type="checkbox" value='0' id="rule_result_check">
					</tr>
				</table>
			</form>
		</div>
	</div>
	
	<!-- 修改 -->
	<div id="update-rule_result" class="easyui-dialog" title="规则结果"
		data-options="
         width:400,
         height:290,
	     resizable:false,
	     modal:true,
	     closed:true,
	     buttons:[{
				text:'保存',
				width:60,
				handler:function(){
					$('#rule_result_add').form({
						
						url:'to_update_rule_result',
						onSubmit:function(params){
							params['attruId']=$('#rule_result_id_update').textbox('getText');
							params['attruName']=$('#rule_result_name_update').textbox('getText');
							params['attruRepeat']=$('#cfyx-value_update').val();
							params['attruAffair']=$('#lb-rule_result_update').val();
							if($('#rule_result_check_update').is(':checked')){
								params['attruState']=parseInt(1);
							}else{
								params['attruState']=parseInt(0);
							}
							params['attruRemarks']=$('#rule_result_marks_update').val();
							alert(params['attruState']);
								return $('#rule_result_update').form('validate');
						},
						success:function(v){
							v = eval('('+v +')');
							if(v.success){
								$.messager.alert('恭喜', '修改成功');
							}else{
								$.messager.alert('错误', '对不起，操作失败，原因：' + v.message);
							}
						$.messager.progress('close');// 如果提交成功则隐藏进度条
						$('#rule_result_tb').datagrid('reload');
						$('#rule_result_add').form('reset');
						$('#update-rule_result').dialog('close');
						}
					}).submit();
				}
				},{
				text:'取消',
				width:60,	
				handler:function(){
					$('#update-rule_result').dialog('close');
				}
			}]
        ">
		<div style="margin-left: 16%; margin-top: 10px;">
			<form action="" id="rule_result_update" style="text-align: right;">
				<table>
					<tr style="display:none;">
						<td><span style="color: red;">*</span>编号</td>
						<td><input class="easyui-textbox"
							name="attruId" data-options="required:true" id="rule_result_id_update"></td>
					</tr>
					<tr>
						<td><span style="color: red;">*</span>名称</td>
						<td><input class="easyui-textbox"
							name="attruName" data-options="required:true" id="rule_result_name_update"></td>
					</tr>
					<!-- <tr>
						<td><span style="color: red;"> </span>简称</td>
						<td><input class="easyui-textbox"></td>
					</tr> -->
					<tr>
						<td><span style="color: red;"> </span>重复有效</td>
						<td>
							<select id="cfyx-value_update" class="easyui-combobox" class="cfyx"
								name="attruRepeat" style="width: 170px;" data-options="panelHeight:'auto'">
									<option value=""> </option>
									<option value="不考虑">不考虑</option>
									<option value="第一个">第一个</option>
									<option value="最后一个">最后一个</option>
							</select>
						</td>
					</tr>
					<tr>
						<td><span style="color: red">*</span>类别</td> 
						<td><select id="lb-rule_result_update" class="easyui-combobox" class="work_leibie_update"
								name="attruAffair"style="width: 170px;" data-options="panelHeight:'auto'">
									<option value="上班">上班</option>
									<option value="下班">下班</option>
									<option value="无">无</option>
							</select></td>
					</tr>
					<tr>
						<td><span style="color: red;"> </span>备注</td>
						<td><input class="easyui-textbox" name="attruRemarks" data-options="height:60,multiline:true" id="rule_result_marks_update"></td>
					</tr>
					<tr>
					
						<td><span style="color: red;"> </span></td>
						<td><span style="padding-right:5px;">停用</span>
						<input name="attruState" type="checkbox" value='1' id="rule_result_check_update">
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>